package com.huynv.redblue;

//import com.google.ads.*;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdSize;
import com.google.android.gms.ads.AdView;
import com.huynv.redblue.PlayGame;
import com.huynv.redblue.MainActivity;

import android.media.AudioManager;
import android.media.ToneGenerator;
import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.view.*;
import android.widget.RelativeLayout;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;

public class MainActivity extends Activity {
	private AdView adView;
	private String MY_AD_UNIT_ID="ca-app-pub-6575239088642506/1558548874";//"a153131675c8136";
	private AlertDialog alertDialog;	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);		
		showAd();
	}
	
	public void launchDrawShapes1(View clickedButton) {
		Intent activityIntent = 
		new Intent(this, PlayGame.class);
		startActivity(activityIntent);
	}
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}
	public void showAd(){
	    adView = new AdView(this);
	    adView.setAdSize(AdSize.BANNER);	   
	    adView.setAdUnitId(MY_AD_UNIT_ID);
	    RelativeLayout rl = new RelativeLayout(this);
	    RelativeLayout.LayoutParams lay = new RelativeLayout.LayoutParams(
	        RelativeLayout.LayoutParams.FILL_PARENT, 
	        RelativeLayout.LayoutParams.WRAP_CONTENT);
	    lay.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);	    
	    RelativeLayout layout = (RelativeLayout) findViewById(R.id.mainLinearLayout1);
	    layout.addView(adView,lay);
	    AdRequest adRequest = new AdRequest.Builder().build();
	    adView.loadAd(adRequest);
    //myView.addView(adView);
	}
	public void onBackPressed()
	{
		AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);

    	// 2. Chain together various setter methods to set the dialog characteristics
    	builder.setMessage("Are you sure to quit?")    	       
    	       .setCancelable(false)
			   .setPositiveButton("Yes",new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog,int id) {
						
						MainActivity.this.finish();
				    	System.exit(0);
					}
				 }).setNegativeButton("No",new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog,int id) {
						// if this button is clicked, close
						// current activity
						alertDialog.hide();
					}
				 });

    	// 3. Get the AlertDialog from create()
    	alertDialog= builder.create();
    	alertDialog.show();
		
	}
	
}
